package com.ruoyi.livedemo.context;

import com.ruoyi.livedemo.entity.User;

public final class CurrentUserHolder {
    private static final ThreadLocal<User> HOLDER = new ThreadLocal<>();

    private CurrentUserHolder() {
    }

    public static void set(User user) {
        HOLDER.set(user);
    }

    public static User get() {
        return HOLDER.get();
    }

    public static Long getUserId() {
        User user = HOLDER.get();
        return user != null ? user.getId() : null;
    }

    public static void clear() {
        HOLDER.remove();
    }
}

